package com.threadExample;

import java.util.concurrent.locks.AbstractQueuedSynchronizer;

/**
 * Created by yijy on 2017/7/27.
 */
public class Machine extends Thread{
    private int a=1;

    @Override
    public void run() {
        synchronized (this){
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                throw new  RuntimeException();
            }
            a=1/0;
            a++;
        }
    }

    public synchronized void print(){
        System.out.println("a="+a);
    }
    public static void main(String[] args) {
        Machine machine = new Machine();
        machine.start();
        Thread.yield();
        machine.print();
    }
}
